package com.eastfair.venueservice.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.boot.request.PageParams;
import com.eastfair.boot.service.SuperService;
import com.eastfair.builder.vo.ExhibitorVO;
import com.eastfair.core.exception.BizException;
import com.eastfair.venueservice.dto.ServiceProviderAuditDTO;
import com.eastfair.venueservice.dto.ServiceProviderDTO;
import com.eastfair.venueservice.entity.ServiceProvider;
import com.eastfair.venueservice.enumeration.ServiceProviderRoleEnum;
import com.eastfair.venueservice.enumeration.ServiceProviderTypeEnum;
import com.eastfair.venueservice.exceptioncode.VenueServiceExceptionCode;
import com.eastfair.venueservice.vo.ExhibitionServiceProviderVO;
import com.eastfair.venueservice.vo.ServiceProviderVO;

import java.util.List;

/**
 * <p>
 * 业务接口
 * 服务商信息表
 * </p>
 *
 * @author gj
 * @date 2022 -07-13
 */
public interface ServiceProviderService extends SuperService<ServiceProvider> {

    /**
     * 分页查询服务商列表VO.
     *
     * @param serviceProviderDTO the service provider dto
     * @return the page
     */
    IPage<ServiceProviderVO> listServiceProviderVOs(PageParams<ServiceProviderDTO> serviceProviderDTO);

    /**
     * 查询服务商列表VO.
     *
     * @param query the query
     * @return the list
     */
    List<ServiceProviderVO> listServiceProviderVOs(ServiceProviderDTO query);

    /**
     * cms同步查询服务商列表
     *
     * @return list
     */
    List<ServiceProviderVO> queryCrmSyncServiceProvider();

    /**
     * 查询服务商列表.
     *
     * @param query the query
     * @return the list
     */
    List<ServiceProvider> listServiceProviders(ServiceProviderDTO query);

    /**
     * ID列表获取服务商列表.
     *
     * @param ids the ids
     * @return the list
     */
    List<ServiceProviderVO> listServiceProviderByIds(List<Long> ids);

    /**
     * 查询待失效服务商列表.
     *
     * @param serviceProviderType the service provider type
     * @return the list
     */
    List<ServiceProvider> listWaitingDisableServiceProviders(String serviceProviderType);

    /**
     * 主场查询负责的搭建商
     *
     * @param homeId       the home id
     * @param exhibitionId the exhibition id
     * @return the list
     */
    List<ExhibitorVO> listBuilderByHomeId(Long homeId, Long exhibitionId);

    /**
     * 条件获取服务商.
     *
     * @param query the query
     * @return the service provider
     */
    ServiceProvider getServiceProvider(ServiceProviderDTO query);

    /**
     * 用户ID，服务商类型 查询服务商注册信息.
     *
     * @param userId              the user id
     * @param serviceProviderType the service provider type
     * @return the service provider by user id
     */
    ServiceProvider getByUserId(Long userId, String serviceProviderType);

    /**
     * 获取用户注册的首个服务商.
     *
     * @param userId the user id
     * @return the first register by user id
     */
    ServiceProvider getFirstRegisterByUserId(Long userId);

    /**
     * 公司名称查询服务商.
     *
     * @param companyName         the company name
     * @param serviceProviderType the service provider type
     * @return the by company name
     */
    ServiceProvider getByCompanyName(String companyName, String serviceProviderType);

    /**
     * 统一社会信用代码查询服务商.
     *
     * @param uscc                the uscc
     * @param serviceProviderType the service provider type
     * @return the by uscc
     */
    ServiceProvider getByUscc(String uscc, String serviceProviderType);

    /**
     * 用户ID，服务商类型 查询有效的服务商注册信息.
     *
     * @param userId              the user id
     * @param serviceProviderType the service provider type
     * @return the list
     */
    ServiceProvider getEnableByUserId(Long userId, String serviceProviderType);

    /**
     * 用户ID，服务商类型 查询服务商.
     *
     * @param userId              the user id
     * @param serviceProviderType the service provider type
     * @return the service provider vo by user id
     */
    ServiceProviderVO getServiceProviderVOByUserId(Long userId, String serviceProviderType);

    /**
     * id 查询服务商详情.
     *
     * @param id the id
     * @return the service provider vo by id
     */
    ServiceProviderVO getServiceProviderVOById(Long id);

    /**
     * 提交服务商信息.
     *
     * @param serviceProviderDTO the service provider dto
     * @return the boolean
     */
    boolean submitServiceProvider(ServiceProviderDTO serviceProviderDTO);

    /**
     * 保存服务商(发起审核).
     *
     * @param serviceProviderDTO the service provider dto
     * @return the boolean
     */
    ServiceProvider saveServiceProvider(ServiceProviderDTO serviceProviderDTO);

    /**
     * 保存服务商.
     *
     * @param serviceProviderDTO 服务商
     * @param isAudit            是否发起审核
     * @return the boolean
     */
    ServiceProvider saveServiceProvider(ServiceProviderDTO serviceProviderDTO, boolean isAudit);

    /**
     * 更新服务商基本信息.
     *
     * @param serviceProviderDTO the service provider dto
     * @return the boolean
     */
    boolean updateServiceProvider(ServiceProviderDTO serviceProviderDTO);

    /**
     * 更新服务商.
     *
     * @param serviceProviderDTO the service provider dto
     * @return the boolean
     */
    boolean updateServiceProviderForAudit(ServiceProviderDTO serviceProviderDTO);

    /**
     * 更新失效的服务商.
     *
     * @param serviceProviderDTO the service provider dto
     * @return the boolean
     */
    boolean updateDisableServiceProvider(ServiceProviderDTO serviceProviderDTO);

    /**
     * 更新服务商为申报中.
     *
     * @param serviceProviderDTO the service provider dto
     * @return the boolean
     */
    boolean updateServiceProviderReporting(ServiceProviderDTO serviceProviderDTO);

    /**
     * 更新服务商审核状态.
     *
     * @param auditDTO the audit dto
     * @return the boolean
     */
    boolean updateAuditStatus(ServiceProviderAuditDTO auditDTO);

    /**
     * 按照服务商类型更新服务商为已失效.
     *
     * @param serviceProviderType the service provider type
     * @return the boolean
     */
    boolean updateServiceProviderDisableByType(String serviceProviderType);

    /**
     * 更新同一服务商类型的服务商为失效.
     *
     * @param list                the wait disable for type list
     * @param serviceProviderType the service provider type
     * @return the boolean
     */
    boolean updateServiceProviderDisableByType(List<ServiceProvider> list, String serviceProviderType);

    /**
     * 更新服务商信用分值.
     *
     * @param serviceProviderDTO the service provider dto
     * @return the boolean
     */
    boolean updateCreditScore(ServiceProviderDTO serviceProviderDTO);

    /**
     * 更新服务商信用分值.
     *
     * @param id    the id
     * @param score the score
     * @return the boolean
     */
    boolean updateCreditScore(Long id, Integer score);

    /**
     * 更新服务商crm同步状态为已同步.
     *
     * @param ids the ids
     * @return the boolean
     */
    boolean updateCrmHasSync(List<Long> ids);

    /**
     * 添加服务商角色.
     *
     * @param serviceProviderType the service provider type
     * @param userId              the user id
     * @param serviceProviderId   the service provider id
     * @return the boolean
     */
    boolean addServiceProviderRole(String serviceProviderType, Long userId, Long serviceProviderId, String serviceProviderName);

    /**
     * 批量移除服务商角色.
     *
     * @param list                the list
     * @param serviceProviderType the service provider type
     * @return the boolean
     */
    boolean removeBatchServiceProviderRole(List<ServiceProvider> list, String serviceProviderType);

    /**
     * 复制服务商为新类型的服务商.
     *
     * @param sourceServiceProvider     the source service provider
     * @param targetServiceProviderType the target service provider
     * @return the boolean
     */
    ServiceProvider copyNewTypeServiceProvider(ServiceProvider sourceServiceProvider, String targetServiceProviderType);

    /**
     * 服务商类型获取服务商常规角色.
     *
     * @param serviceProviderRole the service provider role
     * @return the service provider role
     */
    static ServiceProviderRoleEnum getServiceProviderCommonRole(String serviceProviderRole) {
        if (StrUtil.isBlank(serviceProviderRole)) {
            throw BizException.wrap(VenueServiceExceptionCode.SERVICE_PROVIDER_TYPE_NOT_NULL);
        }
        if (ServiceProviderTypeEnum.MATCHING_SERVICE_PROVIDER.getCode().equals(serviceProviderRole)) {
            return ServiceProviderRoleEnum.MATCHING_COMMON_ROLE;
        }
        if (ServiceProviderTypeEnum.BUILD_SERVICE_PROVIDER.getCode().equals(serviceProviderRole)) {
            return ServiceProviderRoleEnum.BUILD_COMMON_ROLE;
        }
        if (ServiceProviderTypeEnum.HOME_SERVICE_PROVIDER.getCode().equals(serviceProviderRole)) {
            return ServiceProviderRoleEnum.HOME_COMMON_ROLE;
        }
        if (ServiceProviderTypeEnum.MAIN_TRANSPORT_SERVICE_PROVIDER.getCode().equals(serviceProviderRole)) {
            return ServiceProviderRoleEnum.MAIN_TRANSPORT_COMMON_ROLE;
        }
        return null;
    }

    /**
     * 查询展会未同步的所有展会服务商关系
     * @return List<ExhibitionServiceProviderVO>
     */
    List<ExhibitionServiceProviderVO> queryNeedSyncExhibitionProvider();

    /**
     * 查询服务商id集合
     * @param params params
     * @return List<Long>
     */
    List<Long> queryServiceProviderIds(ServiceProviderDTO params);
}
